﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace QSearcher.QServicer.Services
{
    [WebService(Namespace = "http://www.jianghome.crawler.cn/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class CrawlerServicer : System.Web.Services.WebService
    {
        private static object _lock = new object();
        private BLL.Crawler bllCrawler = new BLL.Crawler();

        static CrawlerServicer()
        {
        }

        #region v0.1
        [WebMethod]
        public void SetStartUrl(string crawler, string url)
        {
            lock (_lock) bllCrawler.AddRequestUrl(crawler, url);
        }

        [WebMethod]
        public DAL.Crawler_Url GetRequestUrl()
        {
            lock (_lock) return bllCrawler.GetRequestUrl();
        }

        [WebMethod]
        public void SendRequestResult(string id, string tag = "")
        {
            lock (_lock) bllCrawler.SendRequestResult(id, tag);
        }

        [WebMethod]
        public DAL.Crawler_Url GetDownloadUrl()
        {
            lock (_lock) return bllCrawler.GetDownloadUrl();
        }

        [WebMethod]
        public void SendDownloadResult(string id, string tag = "")
        {
            lock (_lock) bllCrawler.SendDownloadResult(id, tag);
        }

        [WebMethod]
        public DAL.Crawler_Url GetAnalyzeSource(string crawler)
        {
            lock (_lock) return bllCrawler.GetAnalyzeSource(crawler);
        }

        [WebMethod]
        public void SendAnalyzeResult(string id, string[] requestUrls, string[] downloadUrls, string tag = "")
        {
            lock (_lock) bllCrawler.SendAnalyzeResult(id, requestUrls, downloadUrls, tag);
        }
        #endregion

        #region v1.0
        [WebMethod]
        public void SetStartUrl2(string crawler, string url)
        {
        }

        public class RequestUrl
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public RequestUrl GetRequestUrl2()
        {
            return null;
        }

        public class RequestResult
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public void SendRequestResult(RequestResult result)
        {
        }

        public class DownloadUrl
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public DownloadUrl GetDownloadUrl2()
        {
            return null;
        }

        public class DownloadResult
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public void SendDownloadResult(DownloadResult result)
        {
        }

        public class AnalyzeSource
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public AnalyzeSource GetAnalyzeSource2(string crawler)
        {
            return null;
        }

        public class AnalyzeResult
        {
            public int Code { set; get; }
            public string Msg { set; get; }
        }

        [WebMethod]
        public void SendAnalyzeResult(AnalyzeResult result)
        {
        }
        #endregion
    }
}
